<template>
    <el-select
        v-model="optionValue"
        filterable clearable
        placeholder="请选择主教府"
    >
        <el-option
            v-for="item in lists"
            :key="item.id"
            :label="item.title"
            :value="item.id"
        >
        </el-option>
    </el-select>
</template>

<script>
import { getParishAll } from "../../api/parish.js";
export default {
    props: {
        nowValue: {
            type: [Number,String],
            default: ''
        },
        diocese_id: {
            type: [Number],
            default: 0
        }
    },
    data() {
        return {
            lists: [],
            optionValue: 0
        };
    },
    created(){
      this.setList();
      this.optionValue = this.nowValue;
    },
    watch: {
        nowValue(newValue) {
            this.optionValue = newValue;
        },
        optionValue(newValue) {
            this.$emit("update:nowValue", newValue);
        },
        diocese_id(newValue) {
          this.setList(newValue);
        }
    },
    methods: {
        setList(diocese_id = 0) {
            if (diocese_id == 0) diocese_id = this.diocese_id;
            if(diocese_id == 0) return;
            getParishAll({diocese_id}).then(res => {
                if(res.status==200 && res.data.data){
                  this.lists=res.data.data;
                }
            });
        }
    }
};
</script>
